float4x4 World;
float4x4 View;
float4x4 Projection;

struct VertexShaderInput
{
	float4 Position : POSITION;
};

struct VertexShaderOutput
{
     float4 Position : POSITION;
     float Distance : TEXCOORD0;
};
 
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output = (VertexShaderOutput)0;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
   
    output.Distance.x = 1-(output.Position.z/output.Position.w); 
 
    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
{
    return float4(input.Distance.x,0,0,1);
}

technique DepthMapShader
{
     pass P0
     {
        ZEnable = TRUE;
        ZWriteEnable = TRUE;
        AlphaBlendEnable = FALSE;
  
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader  = compile ps_2_0 PixelShaderFunction();
     }
}